package com.zzw.oa.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzw.common.result.Result;
import com.zzw.model.process.ProcessType;
import com.zzw.oa.service.OaProcessTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 审批类型 前端控制器
 * </p>
 *
 * @author zzw
 * @since 2023-05-04
 */
@Api(tags = "流程类型管理")
@RestController
@RequestMapping("admin/oa/processType")
public class OaProcessTypeController {

    @Autowired
    private OaProcessTypeService oaProcessTypeService;


    @ApiOperation(value = "删除流程类型")
    @DeleteMapping("removeType/{id}")
    public Result removeType(@PathVariable Long id) {
        if (oaProcessTypeService.removeById(id)) {
            return Result.ok();
        }
        return Result.fail();
    }


   


    @ApiOperation("添加流程类型")
    @PostMapping("saveType")
    public Result saveType(@RequestBody ProcessType processType) {

        if (oaProcessTypeService.save(processType)) {
            return Result.ok();
        }
        return Result.fail();
    }


    //    修改流程类型的步骤
//    1.根据id查找流程类型
    @ApiOperation("根据id查找流程类型")
    @PostMapping("fidTypeById/{id}")
    public Result<ProcessType> findTypeById(@PathVariable Long id) {
        return Result.ok(oaProcessTypeService.getById(id));
    }

    //    2.最终修改
    @ApiOperation("修改流程类型")
    @PutMapping("updateType")
    public Result updateUser(@RequestBody ProcessType processType) {
        if (oaProcessTypeService.updateById(processType)) {
            return Result.ok();
        }
        return Result.fail();
    }
    //    @RequestBody传入为json格式
    //    json格式中的数组对于java的list集合
    @ApiOperation("批量删除")
    @DeleteMapping("batchRemove")
    public Result batchRemove(@RequestBody List<Long> ids) {
        if (oaProcessTypeService.removeByIds(ids)) {

            return Result.ok();
        }
        return Result.fail();
    }


    @ApiOperation("获取分页列表")
    @GetMapping("{page}/{limit}")
    public Result findPageQueryType(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Long page,
            @ApiParam(name = "limit",value = "每页记录数",required = true)
            @PathVariable Long limit

    )
    {
        Page<ProcessType> pageParam=new Page<>(page,limit);
        IPage<ProcessType> pageMode= oaProcessTypeService.page(pageParam);
        return Result.ok(pageMode);
    }

}

